

//
//  NSString+Extension.m
//  DatangLife
//
//  Created by 娜 on 2018/4/20.
//  Copyright © 2018年 DatangLife. All rights reserved.
//

#import "NSString+Extension.h"

@implementation NSString (Extension)


- (NSString *)noWhiteSpaceString {
    NSString *newString = self;
    //    newString = [newString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];  //去除掉首尾的空白字符和换行字符
    newString = [newString stringByReplacingOccurrencesOfString:@"\r" withString:@""];
    newString = [newString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    newString = [newString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];  //去除掉首尾的空白字符和换行字符使用
    newString = [newString stringByReplacingOccurrencesOfString:@" " withString:@""];
    //    可以去掉空格，注意此时生成的strUrl是autorelease属性的，所以不必对strUrl进行release操作！
    //    newString = [newString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    return newString;
}

//时间戳变为格式时间
+ (NSString *)ConvertStrToTime:(NSString *)timeStr dateFormat:(NSString *)dateFormat{
    
    //    long long time = [timeStr longLongValue];
    // 如果服务器返回的是13位字符串，需要除以1000，否则显示不正确(13位其实代表的是毫秒，需要除以1000) //
    long long time = [timeStr longLongValue] / 1000;
    NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:time];
    
    //    NSDate *date = [[NSDate alloc] initWithTimeIntervalSinceReferenceD ate:time];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:dateFormat];
    NSString*timeString=[formatter stringFromDate:date];
    return timeString;
}

@end
